package com.spr.gw.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.Serializable;

@Data
public class ResultBean<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String msg ;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    public ResultBean() {
        super();
    }
    public ResultBean(int code) {
        super();
        this.code = code;
    }
    public ResultBean(int code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }
    public ResultBean(int code, T data) {
        super();
        this.code = code;
        this.data = data;
    }

    public ResultBean(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultBean<T> createBySuccess(){
        return new ResultBean<T>(ResponseCode.SUCCESS.getCode());
    }
    public static <T> ResultBean<T> createBySuccess(T data){
        return new ResultBean<T>(ResponseCode.SUCCESS.getCode(), data);
    }
    public static <T> ResultBean<T> createBySuccessMessage(String message){
        return new ResultBean<T>(ResponseCode.SUCCESS.getCode(), message);
    }
    public static <T> ResultBean<T> createBySuccessMessage(String message,T data){
        return new ResultBean<T>(ResponseCode.SUCCESS.getCode(), message, data);
    }
    public static <T> ResultBean<T> createByCodeMessage(int code){
        return new ResultBean<T>(code);
    }
    public static <T> ResultBean<T> createByCodeMessage(int code, String message){
        return new ResultBean<T>(code, message);
    }
    public static <T> ResultBean<T> createByCodeMessage(int code, String message, T data){
        return new ResultBean<T>(code, message, data);
    }
}
